package com.zigong.app.ui.activities;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;

import com.canyinghao.canrefresh.CanRefreshLayout;
import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.ui.widget.CustomLinearLayout;
import com.ruihang.generalibrary.utils.ListUtils;
import com.ruihang.generalibrary.utils.UrlUtils;
import com.zigong.app.R;
import com.zigong.app.application.Cache;
import com.zigong.app.application.Constances;
import com.zigong.app.application.SiChuanFocusApplication;
import com.zigong.app.base.BaseActivity;
import com.zigong.app.base.BaseCanPlayActivity;
import com.zigong.app.beans.ADynamicsItem;
import com.zigong.app.beans.AFileItem;
import com.zigong.app.beans.AnchorList;
import com.zigong.app.beans.AnchorRecommendItem;
import com.zigong.app.beans.AuthorFileItem;
import com.zigong.app.beans.FProgramme;
import com.zigong.app.beans.FUsers;
import com.zigong.app.beans.SingleResult;
import com.zigong.app.http.AbsListNetCallback;
import com.zigong.app.http.AbsNetCallBack;
import com.zigong.app.http.NetUtils;
import com.zigong.app.http.ParamsEditor;
import com.zigong.app.ui.adapter.AnchorHomePageAdapter;
import com.zigong.app.ui.adapter.holder.AnchorHomeDynamicsHolder;
import com.zigong.app.ui.util.IListShowData;
import com.zigong.app.ui.utils.SkipUtil;
import com.zigong.app.ui.utils.TitleUtils;
import com.zigong.app.utils.UserManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 主播栏目主页（从fragment改为activity）
 */
public class AnchorActivity extends BaseCanPlayActivity implements CanRefreshLayout.OnRefreshListener, CanRefreshLayout.OnLoadMoreListener
        , CanRefreshLayout.IScrollView {
    @BindView(R.id.fragment_anchor_refresh)
    protected CanRefreshLayout refreshLayout;
    @BindView(R.id.can_content_view)
    protected CustomLinearLayout detail;
    @BindView(R.id.anchor_list)
    protected RecyclerView anchor_list;
    @BindView(R.id.anchor_video_container)
    protected AbsoluteLayout videoContainer;
    @BindView(R.id.layout_title)
    protected View headView;
    @BindView(R.id.iv_item_anchor_title)
    protected ImageView ivHeadView;
    @BindView(R.id.tv_item_anchor_title_name)
    protected CustomFontTextView tvHeadText;
    private AnchorHomePageAdapter adapter;
    private LinearLayoutManager manger;
    private AnchorList item;
    private int otherHeight;
    private Handler handler;
    private MotionEvent mCurrentMotion;
    protected static final int CODE_REQUEST_LOGIN = 303;
    //    protected FloatGSYVideoUtils floatVideoUtils;
    private int dataVersion;
    private String channelUrl;
    private int index = 0;
    private int authorIndex = 0;
    private int otherAuthorIndex = 0;
    private final static int pageSize = 10;
    private int count = 0;
    private final static int totalCount = 30;
    private final static int totalAuchorFileCount = 20;
    public final static String SCTV_AUTHOR_KEY = "SCTV_AUTHOR_KEY";
    public final static String OTHER_AUTHOR_KEY = "OTHER_AUTHOR_KEY";
    public final static String CHANNEL_URL = "channel_url";

    private final static int ANCHOR_SCTV_TYPE = 0;
    private final static int ANCHOR_OTHER__TYPE = 1;
    private List<AnchorRecommendItem> recommendItemList;
    private List<ADynamicsItem> dyDatas;
    private List<IListShowData> allDatas;
    private List<AFileItem> sctvAuthors;
    private List<AFileItem> otherAuthors;
    private AuthorFileItem authorFileItem;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this);
        handler = new Handler();
        initViews();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_anchor);
        ButterKnife.bind(this);
    }

    protected void initViews() {
        channelUrl = getIntent().getStringExtra(CHANNEL_URL);
//        floatVideoUtils = new FloatGSYVideoUtils(this, parentView, videoLayout, otherHeight);
//        floatVideoUtils.setPlayerFactor(new FloatGSYVideoUtils.IPlayerFactor() {
//            @Override
//            public BasePlayerView createPlayerView() {
//                BasePlayerView bpv = createdPlayerView();
//                initVideoPlayer(bpv);
//                return bpv;
//            }
//        });
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setOnLoadMoreListener(this);
        refreshLayout.setLoadMoreEnabled(false);
        manger = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        anchor_list.setItemAnimator(new DefaultItemAnimator());
        anchor_list.setLayoutManager(manger);
        detail.setiScrollView(this);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SkipUtil.REQUEST_CODE_PLAY_BASE) {
            if (data != null || adapter != null) {
                int pos = data.getIntExtra(VideoPlayActivity.EXTRA_POS_ITEM, -1);
                if (pos >= 0) {
                    ADynamicsItem item = (ADynamicsItem) adapter.getItem(pos);
                    if (item == null) {
                        return;
                    }
                    if (resultCode == RESULT_OK) {
                        item.setPlayedPos(0);
                    } else {
                        int playedPos = data.getIntExtra(VideoPlayActivity.EXTRA_POS, -1);
                        if (playedPos > 0) {
                            item.setPlayedPos(playedPos);
                        }
                    }
                }
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        refreshLayout.autoRefresh();
    }

    @Override
    public void onDestroy() {
        if (floatVideoUtils != null) {
            anchor_list.removeOnScrollListener(floatVideoUtils.getRecyclerScrollListener());
        }
        super.onDestroy();
    }


    public boolean hasShowPlayer() {
        return floatVideoUtils != null && floatVideoUtils.isHasInited();
    }

    @Override
    public void onBackPressed() {
        if (floatVideoUtils != null && floatVideoUtils.onBackPress()) {
            actionToPortrait();
            return;
        }
        super.onBackPressed();
    }

    @Override
    public void onLoadMore() {

    }


    @Override
    public void onRefresh() {
        if (allDatas == null) {
            allDatas = new ArrayList<>();
        } else {
            allDatas.clear();
        }
        index = 0;
        authorIndex = 0;
        otherAuthorIndex = 0;
        getTimeLineList();

    }

    /**
     * 主播动态 数据请求（主播发表的内容）
     */
    private void getTimeLineList() {

        HashMap<String, Object> param = new HashMap<>();
        param.put("anchorId", "");
        param.put("capacity", pageSize);
        param.put("index", index);
        param.put("requestType", ANCHOR_SCTV_TYPE);
        param.put("siteNumber", Constances.SITE_ID);
        FUsers user = UserManager.getInstance().getUser();
        if (user != null && !TextUtils.isEmpty(user.getUserId())) {
            param.put("userId", user.getUserId());
        } else {
            param.put("userId", "");
        }
        NetUtils.getNetAdapter().getTimelineList(getOwnerName(), param, new AbsListNetCallback<ADynamicsItem>(ADynamicsItem.class) {
            @Override
            public void onSuc(List<ADynamicsItem> anchortimelines) {
                if (vMoreTimelist != null) {
                    vMoreTimelist.setEnabled(true);
                }
                if (dyDatas == null) {
                    dyDatas = new ArrayList<>();
                }
                if (index == 0) {//第一次加載或者下拉刷新后 index重置為0；
                    dyDatas.clear();
                    if (ListUtils.isListValued(anchortimelines)) {
                        ADynamicsItem firstItem = anchortimelines.get(0);
                        firstItem.setDynamics(true);
                        firstItem.setSticky(true);
                        if (anchortimelines.size() >= pageSize) {//如果獲取的數據大於10條 則加載更多
                            ADynamicsItem lastItem = anchortimelines.get(anchortimelines.size() - 1);
                            lastItem.setMore(true);
                        }
                        dyDatas.addAll(0, anchortimelines);
                        allDatas.addAll(0, dyDatas);
                    }

                } else {
                    if (allDatas != null && allDatas.containsAll(dyDatas)) {
                        allDatas.removeAll(dyDatas);
                    }
                    dyDatas.get(dyDatas.size() - 1).setMore(false);
                    if (anchortimelines.size() >= pageSize) {//如果獲取的數據大於10條 則加載更多
                        ADynamicsItem lastItem = anchortimelines.get(anchortimelines.size() - 1);
                        lastItem.setMore(true);
                    }
                    dyDatas.addAll(anchortimelines);
                    if (dyDatas.size() >= totalCount) {//加载30条后还有更多则跳转
                        dyDatas.get(dyDatas.size() - 1).setJump(true);
                    }
                    allDatas.addAll(0, dyDatas);
                    if (adapter != null) {
                        adapter.setData(allDatas);
                    }
                }

                if (index == 0) {
                    //请求主播推荐
                    getAnchorPageList();
                }

            }

            @Override
            public List<ADynamicsItem> doInBackground(List<ADynamicsItem> aDynamicsItems) {
                if (aDynamicsItems != null) {
                    for (ADynamicsItem item : aDynamicsItems) {
                        item.setViewType(AnchorHomePageAdapter.VIEWTYPE_DYNAMICS);
                    }
                }

                return super.doInBackground(aDynamicsItems);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (vMoreTimelist != null) {
                    vMoreTimelist.setEnabled(true);
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                if (vMoreTimelist != null) {
                    vMoreTimelist.setEnabled(true);
                }
                refreshLayout.refreshComplete();
            }
        });


    }


    /**
     * 主播推荐数据请求
     */
    private void getAnchorPageList() {
        if (TextUtils.isEmpty(channelUrl)) {
            toast("数据错误");
            JLog.e("int " + this.getClass().getSimpleName() + " url wrong ::" + channelUrl);
            refreshLayout.refreshComplete();
            return;
        }
        NetUtils.getNetAdapter().getAnchorList(getOwnerName(), channelUrl, new AbsNetCallBack<AnchorList>(AnchorList.class) {


            @Override
            public void onSuc(AnchorList anchorList) {
                if (anchorList != null) {
                    JLog.e("====anchor==" + anchorList.toString());
                    item = anchorList;
                    setAnchorData(anchorList, recommendItemList);
                    if (index == 0) {
                        //请求主播档案
                        getSCTVAnchorList();
                        getOtherAnchorList();
                    }

                }
            }

            @Override
            public AnchorList doInBackground(AnchorList anchorList) {
                if (anchorList != null && ListUtils.isListValued(anchorList.getAnchorNode())) {
                    if (recommendItemList == null) {
                        recommendItemList = new ArrayList<AnchorRecommendItem>();
                        List<FProgramme> list = anchorList.getAnchorNode();
                        AnchorRecommendItem ari = null;
                        int n = 0;
                        for (int i = 0; i < list.size(); i++) {
                            if (n == 0) {
                                if (ari != null) {
                                    recommendItemList.add(ari);
                                }
                                ari = new AnchorRecommendItem(list.get(i), null);
                                ari.setViewType(AnchorHomePageAdapter.VIEWTYPE_RECOMMEND);
                                n++;
                                if (i == 0) {
                                    ari.setStick(true);
                                }
                            } else {
                                ari.setProgramme2(list.get(i));
                                n = 0;
                            }
                            if (i == list.size() - 1 && ari != null) {
                                ari.setLast(true);
                            } else {
                                ari.setLast(false);
                            }
                        }
                        if (ari != null) {
                            recommendItemList.add(ari);
                        }
                    }
                }
                return super.doInBackground(anchorList);
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                refreshLayout.refreshComplete();
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish();
            }
        });
    }

    /**
     * 主播档案
     * 市州主播列表请求
     */
    private void getOtherAnchorList() {
        HashMap<String, Object> param = new HashMap<>();
        param.put("count", pageSize);
        param.put("index", otherAuthorIndex);
        param.put("requestType", 1);
        param.put("siteNumber", Constances.SITE_ID);
        NetUtils.getNetAdapter().getRadioHostDoc(getOwnerName(), param, new AbsListNetCallback<AFileItem>(AFileItem.class) {
            @Override
            public void onSuc(List<AFileItem> aFileItems) {
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
                if (otherAuthors == null) {
                    otherAuthors = new ArrayList<>();
                }
                if (ListUtils.isListValued(aFileItems)) {
                    if (otherAuthorIndex == 0) {
                        otherAuthors.clear();
                    }
                    otherAuthors.addAll(aFileItems);
                }
                if (authorFileItem == null) {
                    authorFileItem = new AuthorFileItem();
                    authorFileItem.setViewType(AnchorHomePageAdapter.VIEWTYPE_FILE);
                }
                authorFileItem.setOtherFileItem(otherAuthors);
                if (aFileItems.size() >= pageSize) {
                    authorFileItem.setOtherMore(true);
                } else {
                    authorFileItem.setOtherMore(false);
                }
                if (otherAuthors.size() >= totalAuchorFileCount) {
                    authorFileItem.setOhterJump(true);
                } else {
                    authorFileItem.setOhterJump(false);
                }
                if (!allDatas.contains(authorFileItem)) {
                    allDatas.add(authorFileItem);
                }
                if (adapter != null) {
                    adapter.setData(allDatas);
                }
            }

            @Override
            public List<AFileItem> doInBackground(List<AFileItem> aFileItems) {

                if (aFileItems != null) {
                    for (AFileItem item : aFileItems) {
                        item.setViewType(AnchorHomePageAdapter.VIEWTYPE_FILE);
                    }
                }
                return super.doInBackground(aFileItems);
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
                refreshLayout.refreshComplete();
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
            }
        });

    }

    /**
     * 主播档案
     * 川台主播列表请求
     */
    private void getSCTVAnchorList() {
        HashMap<String, Object> param = new HashMap<>();
        param.put("count", pageSize);
        param.put("index", authorIndex);
        param.put("requestType", 0);
        param.put("siteNumber", Constances.SITE_ID);

        NetUtils.getNetAdapter().getRadioHostDoc(getOwnerName(), param, new AbsListNetCallback<AFileItem>(AFileItem.class) {
            @Override
            public void onSuc(List<AFileItem> aFileItems) {
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
                if (sctvAuthors == null) {
                    sctvAuthors = new ArrayList<>();
                }
                if (ListUtils.isListValued(aFileItems)) {
                    if (authorIndex == 0) {
                        sctvAuthors.clear();
                    }
                    sctvAuthors.addAll(aFileItems);
                }
                if (authorFileItem == null) {
                    authorFileItem = new AuthorFileItem();
                    authorFileItem.setViewType(AnchorHomePageAdapter.VIEWTYPE_FILE);
                }
                authorFileItem.setSctvFileItem(sctvAuthors);
                if (aFileItems.size() >= pageSize) {
                    authorFileItem.setSctvMore(true);
                } else {
                    authorFileItem.setSctvMore(false);
                }
                if (sctvAuthors.size() >= totalAuchorFileCount) {
                    authorFileItem.setSctvJump(true);
                } else {
                    authorFileItem.setSctvJump(false);
                }
                if (!allDatas.contains(authorFileItem)) {
                    allDatas.add(authorFileItem);
                }

                if (adapter == null) {
                    adapter = new AnchorHomePageAdapter(AnchorActivity.this, allDatas).setItemInternalClick(circleOnClick);
                    adapter.setPlayClick(playClick);
                    adapter.setActivity(AnchorActivity.this);
                    ArrayList<Pair<String, String>> pairs = new ArrayList<>();
                    pairs.add(new Pair<>("页面", "首页"));
                    pairs.add(new Pair<>("栏目", "主播"));
                    pairs.add(new Pair<>("行为类型", "点击"));
                    adapter.setPairs(pairs);
                    anchor_list.setAdapter(adapter);
                    anchor_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
                        @Override
                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                            super.onScrolled(recyclerView, dx, dy);

                            View stickyInfoView = recyclerView.findChildViewUnder(
                                    headView.getMeasuredWidth() / 2, 5);

                            if (stickyInfoView != null && stickyInfoView.getContentDescription() != null) {
                                tvHeadText.setText(String.valueOf(stickyInfoView.getContentDescription()));
                                if (tvHeadText.getText().equals("主播动态")) {
                                    ivHeadView.setVisibility(View.VISIBLE);
                                }
                            }

                            View transInfoView = recyclerView.findChildViewUnder(
                                    headView.getMeasuredWidth() / 2, headView.getMeasuredHeight() + 1);

                            if (transInfoView != null && transInfoView.getTag() != null) {

                                int transViewStatus = (int) transInfoView.getTag();
                                int dealtY = transInfoView.getTop() - headView.getMeasuredHeight();

                                if (transViewStatus == AnchorHomePageAdapter.HAS_STICKY_VIEW) {
                                    if (transInfoView.getTop() > 0) {
                                        headView.setTranslationY(dealtY);
                                    } else {
                                        ivHeadView.setVisibility(View.GONE);
                                        headView.setTranslationY(0);
                                    }
                                } else if (transViewStatus == AnchorHomePageAdapter.NONE_STICKY_VIEW) {
                                    headView.setTranslationY(0);

                                }
                            }
                        }
                    });
                } else {
                    adapter.setData(allDatas);
                }
            }

            @Override
            public List<AFileItem> doInBackground(List<AFileItem> aFileItems) {
                if (aFileItems != null) {
                    for (AFileItem item : aFileItems) {
                        item.setViewType(AnchorHomePageAdapter.VIEWTYPE_FILE);
                    }
                }
                return super.doInBackground(aFileItems);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                if (vMoreAnchorFile != null) {
                    vMoreAnchorFile.setEnabled(true);
                }
            }
        });

    }

    private synchronized void onNetFinish() {
        if (refreshLayout.isRefreshing()) {
            refreshLayout.refreshComplete();
        }
    }

    public void setAnchorData(AnchorList anchorData, List<AnchorRecommendItem> recommendList) {
        dataVersion = ((SiChuanFocusApplication) getApplication()).getDatasVersionManager().getVersion(Constances.DATA_VERSION_ADYNAMIC);
        if (ListUtils.isListValued(recommendList)) {
            allDatas.addAll(recommendList);
        }
    }

    OnItemInternalClick circleOnClick = new OnItemInternalClick() {
        @Override
        public void onItemInternalClick(View itemView, View view, int position) {
            Intent intent = new Intent(AnchorActivity.this, AnchorCircleActivity.class);
            if (!TextUtils.isEmpty(item.getAnchorLoopEntry())) {

                intent.putExtra(BaseActivity.EX_HTML, item.getAnchorLoopEntry());
            }
            startActivity(intent);
        }
    };


    OnItemInternalClick playClick = new OnItemInternalClick() {
        @Override
        public void onItemInternalClick(View itemView, View view, int position) {
            itemClick(itemView, view, position);
        }
    };
    private View vMoreTimelist;
    private View vMoreAnchorFile;

    private void itemClick(View itemView, View view, int position) {

        switch (view.getId()) {
            case R.id.item_anchor_home_dynamics_video_play:
                ADynamicsItem dynamics = (ADynamicsItem) adapter.getItem(position);
                contentVideoUrl = UrlUtils.linkUrls(Constances.ST_BASE_URL, dynamics.getContentVideo());
                SkipUtil.skipToVideoPlayWithCover(this, contentVideoUrl, dynamics.getPlayedPos(), position,dynamics.getVideoImage().getImageUrl());
                break;
            case R.id.tv_anchor_dynamics_home_page_more:
                vMoreTimelist = view;
                view.setEnabled(false);
                ADynamicsItem dy = (ADynamicsItem) adapter.getItem(position);
                if (dy.isJump()) {
                    Intent intent = new Intent(AnchorActivity.this, AnchorDyListActivity.class);
                    startActivity(intent);
                } else {
                    index++;
                    getTimeLineList();
                }
                break;

            case R.id.tv_anchor_up:
                if (!UserManager.isLoginS()) {
                    toLogin();
                    return;
                }
                ADynamicsItem dyUp = (ADynamicsItem) adapter.getItem(position);
//                if (dyUp.getAttitudesStatus()) {
//                    toast("已经点过赞啦");
//                    return;
//                }
                doUp(dyUp, position);
                break;
            case R.id.tv_anchor_comment:
//                toast("跳转至评论列表");
                ADynamicsItem adi = (ADynamicsItem) adapter.getItem(position);
                Intent intent = new Intent(AnchorActivity.this, CommentDetailActivity.class);
                intent.putExtra(EX_DATA, adi);
                intent.putExtra(EX_COMMENT_TYPE, 3);
                startActivity(intent);
                break;

            case R.id.tv_anchor_file_more:
                vMoreAnchorFile = view;
                view.setEnabled(false);
                AuthorFileItem item = (AuthorFileItem) adapter.getItem(position);
                boolean isSctv = (boolean) view.getTag();
                if (isSctv) {
                    authorIndex += pageSize;
                    getSCTVAnchorList();
//                    }
                } else {
                    otherAuthorIndex += pageSize;
                    getOtherAnchorList();
//                    }
                }
                break;
            case R.id.rb_auchor_file_other:
                otherAuthorIndex = 0;
                getOtherAnchorList();
                break;
            case R.id.rb_auchor_file_sctv:
                authorIndex = 0;
                getSCTVAnchorList();
                break;
        }

    }

    private AnchorHomeDynamicsHolder lastHolder;

    private void doUp(final ADynamicsItem aDynamicsItem, int position) {
        RecyclerView.LayoutManager manager = anchor_list.getLayoutManager();
        View lastView = manager.findViewByPosition(position);
//        AnchorHomeDynamicsHolder lastHolder = null;
        if (null != lastView && anchor_list.getChildViewHolder(lastView) instanceof AnchorHomeDynamicsHolder) {
            lastHolder = (AnchorHomeDynamicsHolder) anchor_list.getChildViewHolder(lastView);
            if (null != lastHolder) {
                lastHolder.getTvUp().setDrawableEnlarge();
            }
        }

        ParamsEditor pe = new ParamsEditor();
//        HashMap<String, Object> param = new HashMap<>();
        pe.put("dynamicId", aDynamicsItem.getDynamicId());
        pe.put("fType", 1);//1 主播 2报料 3新闻(短视频) 4 直播
//        pe.put("token", UserManager.getInstance().getToken());
        pe.put("userId", UserManager.getInstance().getUser().getUserId());

        NetUtils.getNetAdapter().doUpForDynamics(getOwnerName(), pe.getEncryptedParams(UserManager.getInstance().getToken()), new AbsNetCallBack<SingleResult>(SingleResult.class) {
            @Override
            public void onSuc(SingleResult singleResult) {
                if (singleResult.isSuccess()) {
                    SkipUtil.skipToAddUserOperate(AnchorActivity.this, getOwnerName(), 13, 2, "主播圈点赞", aDynamicsItem.getDynamicId(), Cache.getInstance().getCurrentChannelId());
                    for (ADynamicsItem item : dyDatas) {
                        if (item.getDynamicId().equals(aDynamicsItem.getDynamicId())) {
                            item.setAttitudesCount(aDynamicsItem.getAttitudesStatus() ? aDynamicsItem.getAttitudesCount() - 1 : aDynamicsItem.getAttitudesCount() + 1);
                            item.setAttitudesStatus(!aDynamicsItem.getAttitudesStatus());
                            adapter.notifyDataSetChanged();
                            if (item.getAttitudesStatus()) {
                                addInvitation(Constances.ADD_INTEGRAL_DOUP, false);
                            }
                        }
                    }
                }
            }
        });
    }


    @Override
    public boolean canScrollUp(MotionEvent motionEvent) {
        return ViewCompat.canScrollVertically(anchor_list, -1);
    }

    @Override
    public boolean canScrollDown(MotionEvent motionEvent) {
        return ViewCompat.canScrollVertically(anchor_list, 1);
    }

    protected void toLogin() {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivityForResult(intent, CODE_REQUEST_LOGIN);
    }

}

